<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图片预加载</title>
    <style>
        img {
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
<script>
    let imgArr = [
        'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1590919117150&di=e1e428c54bd6181db14359bf7ee3c42e&imgtype=0&src=http%3A%2F%2Ft9.baidu.com%2Fit%2Fu%3D1307125826%2C3433407105%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D5760%26h%3D3240',
        'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1590919117150&di=6998388a9885247d8c3ca61ba303221c&imgtype=0&src=http%3A%2F%2Ft9.baidu.com%2Fit%2Fu%3D2268908537%2C2815455140%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D1280%26h%3D719',
        'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1590919115925&di=5668de27ba23d6e53991b95362540878&imgtype=0&src=http%3A%2F%2Ft9.baidu.com%2Fit%2Fu%3D583874135%2C70653437%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D3607%26h%3D2408',
        'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1590919197536&di=cadd084f0093b1381afd934d790b2c3c&imgtype=0&src=http%3A%2F%2Ft9.baidu.com%2Fit%2Fu%3D3363001160%2C1163944807%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D1280%26h%3D830',
        'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1590919218405&di=5f26adb46cd47e5389d74b68269099c6&imgtype=0&src=http%3A%2F%2Ft7.baidu.com%2Fit%2Fu%3D1179872664%2C290201490%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D1280%26h%3D854',
        'https://sdadas.ss'
    ]
    let count = 0;
    let img = []
    for (let i = 0; i < imgArr.length; i++) {
        let image = new Image()
        image.src = imgArr[i]
        image.onload = image.onerror = function (e) {
            if (e.type === "load") {
                img.push(e.path[0]);
            }
            count++;
            if (count === imgArr.length) {
                alert("加载完毕")
                for (let j = 0; j < img.length; j++) {
                    document.body.append(img[j]);
                }
            }
        }
    }
</script>
</body>
</html>
